using System;
using System.Collections.Generic;
using System.Text;
using QLHXNK.DataAccess;
using System.Data;
namespace QLHXNK.BusinessLogic
{
    class MonthlyExpenses
    {
        private int monthlyExpensesID;
        private int monthName;
        private int yearName;
        private int expensesID;
        private double amount;
        private String remark;

        #region Properties

        public int ID
        {
            get { return monthlyExpensesID; }
        }
        public int MonthName
        {
            get { return monthName; }
            set { monthName = value; }
        }

        public int YearName
        {
            get { return yearName; }
            set { yearName = value; }
        }

        public int ExpensesID
        {
            get { return expensesID; }
            set { expensesID = value; }
        }

        public double Amount
        {
            get { return amount; }
            set { amount = value; }
        }

        public String Remark
        {
            get { return remark; }
            set { remark = value; }
        }

        #endregion

        public MonthlyExpenses(int monthlyExpensesID, int monthName, int yearName, int expensesID, double amount, String remark)
        {
            this.monthlyExpensesID = monthlyExpensesID;
            this.monthName = monthName; 
            this.yearName=yearName;
            this.expensesID = expensesID;
            this.amount = amount;
            this.remark = remark;
        }

        #region ----------------------------------------Lấy thông tin ----------------------------------------

        public static DataTable ListMonthlyExpenses()
        {
            try
            {
                return MonthlyExpensesData.ListMonthlyExpenses();
            }
            catch
            {
                return null;
            }
        }
        public static DataTable GetMonthlyExpensesByMonth(int monthName, int yearName)
        {
            try
            {
                return MonthlyExpensesData.GetMonthlyExpensesByMonth(monthName, yearName,"");
            }
            catch { return null; }
        }
        public static DataTable GetMonthlyExpensesByMonthAndExpexsesCode(int monthName, int yearName, String expensesCode)
        {
            try
            {
                return MonthlyExpensesData.GetMonthlyExpensesByMonth(monthName, yearName, expensesCode);
            }
            catch { return null; }
        }
        #endregion

        #region ------------------------------------------Thêm, xoá, sửa-------------------------------------------

        public static MonthlyExpenses CreateMonthlyExpenses(int monthName, int yearName, int expensesID, double amount, String remark)
        {
            try
            {
                int id = MonthlyExpensesData.CreateMonthlyExpenses(monthName, yearName,expensesID, amount, remark);
                MonthlyExpenses monthlyExpenses = null;
                if (id != 0)
                    monthlyExpenses = new MonthlyExpenses(id, monthName,yearName,expensesID,amount, remark);
                return monthlyExpenses;
            }
            catch
            {
                return null;
            }
        }

        public int DeleteMonthlyExpenses()
        {
            try
            {
                return MonthlyExpensesData.DeleteMonthlyExpenses(this.monthlyExpensesID,-1,-1);
            }
            catch
            {
                return 0;
            }
        }

        public static int DeleteMonthlyExpensesByMonthName(int monthName, int yearName)
        {
            try
            {
                return MonthlyExpensesData.DeleteMonthlyExpenses(-1, monthName, yearName);
            }
            catch
            {
                return 0;
            }
        }

        public int Save()
        {
            try
            {
                return MonthlyExpensesData.UpdateMonthlyExpenses(this.monthlyExpensesID, this.expensesID, this.amount, this.remark);
            }
            catch
            {
                return 0;
            }
        }

        public int UpdateMonthlyExpenses(int expensesID, double amount, String remark)
        {
            try
            {
                this.expensesID = expensesID;
                this.amount = amount;
                this.remark = remark;
                return Save();
            }
            catch
            {
                return 0;
            }
        }

        #endregion
    }
}
